<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
</head>
<body>
    <script src="js/jquery-1.8.3.min.js"></script>

    <form action="" method="post">
        用户名:<input type="text" name="username" id="username"/><br/>
        密码:<input type="text" name="passwords" id="password"/><br/>
        <input type="button" value="登录" id="btn1"/>
    </form>

    <script>
        $(function(){       //表示整个页面加载完之后执行
            //获取按钮，并添加点击事件，发送ajax
            $("#btn1").click(function(){
                let username = $("#username").val();
                let password = $("#password").val();

                $.ajax({
                    url:"/user/login.do",//请求地址
                    type:"POST",//请求方式
                    data:'{"username":"'+username+'","password":"'+password+'"}',//请求参数
                    contentType:"application/json",
                    dataType:"json",//响应正文内容
                    success:function(data){
                        if(data.flag==true){
                           location.href = "success.html" //跳转
                        }else{
                            alert(data.message)
                        }
                    }
                });
            });
        });
    </script>
</body>
</html>